import { createRouter, createWebHistory } from 'vue-router';
import Home from '@/views/home/home.vue';

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
  },
  {
    path: '/about',
    name: 'About',
    component: () => import('@/views/about'),
  },
  {
    path: '/empty',
    name: 'Empty',
    component: () => import('@/views/empty'),
  },
];

export function setupRouter() {
  const base = window.__MICRO_APP_ENVIRONMENT__ ? window.__MICRO_APP_BASE_ROUTE__ : '/subapp-vue3';
  const history = createWebHistory(base);
  const router = createRouter({
    // history: createWebHistory(process.env.BASE_URL),
    history,
    routes,
  });

  // router.beforeEach(() => {
  //   console.log('子路由监听发生变化');
  // });

  return {
    history,
    router,
  };
}
